package cn.gdcp.lkqapp20;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class MyCircle extends View {
    private Paint paint;
    private int progress = 88;

    public MyCircle(Context context, AttributeSet attrs) {
        super(context, attrs);
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.STROKE);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        paint.setColor(Color.RED);
        paint.setStrokeWidth(25);

        canvas.drawCircle(300,800,200,paint);
        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(2);
        paint.setTextSize(80);
        canvas.drawText("" + progress + "%",250,800,paint);

        paint.setStrokeWidth(18);
        canvas.drawArc(100,600,500,1000,270,
                360 * progress/100,false,paint);
    }

    public void setProgress(int progress) {
        this.progress = progress;
        invalidate();
    }
}
